<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>系统用户列表</title>
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/animate.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/style.min.css?v=4.0.0" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/views/sysdefault/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
	
</head>

<body class="gray-bg">
    <!-- 分页 -->
	<form id="pagerForm" method="post" action="listSysUser.do">
		<input type="hidden" name="currentPage" id="currentPage" value="1" />
		<input type="hidden" name="userName" id="userName" value="${dataStore.userName}">
	</form>
    
    
    <div class=" animated fadeInRight">
    	<div class="row">
            <div class="col-sm-12">
                    <div class="ibox-title">
                        <h5>系统用户列表</h5>
                        <div class="ibox-tools">
                            <a class="collapse-link">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                    <form id="listSysUser" name="listSysUser" action="listSysUser.do" method="post">
                    	<div class="m-b-sm">
                    		<div class="col-sm-2">
                    			<div class="input-group">
                    				<span class="input-group-addon">名字</span>
									<input type="text" class="form-control" name="userName" id="userName" value="${dataStore.userName}"/>
								</div>
							</div>
                    		<button type="submit" class="btn btn-info" ><i class="fa fa-times-circle"></i>&nbsp;&nbsp;搜索</button>
                    	</div>
                    </form>
                    
                    	<div class="m-b-sm">
                    		<button type="button" class="btn btn-success btn-sm hidden-xs" onclick="addUser();"><i class="fa fa-plus-square"></i>&nbsp;&nbsp;添加</button>
                    		<button type="button" class="btn btn-danger btn-sm" onclick="delUser();"><i class="fa fa-times-circle"></i>&nbsp;&nbsp;删除</button>
                    	</div>

						<div class="m-b-sm">
							<table id="table" data-toggle="table" data-mobile-responsive="true" >
								<thead>
									<tr>
										<th data-checkbox="true" data-width="2%"></th>
										<th data-visible="false">userId</th>
										<th data-width="5%" data-align="center">序号</th>
										<th data-width="10%">账号</th>
										<th data-width="23%">名字</th>
										<th data-width="40%">单位(职位)</th>
										<th data-width="10%" data-align="center">用户状态</th>
										<th data-width="10%" data-align="center">操作</th>
									</tr>
								</thead>
								<tbody>
									<c:forEach items="${pageInfo.resultList}" var="item" varStatus="i">
										<tr>
											<td></td>
											<td>${item.userId}</td>
											<td>${i.index + 1}</td>
											<td>${item.userAccount}</td>
											<td>${item.userName}</td>
											<td>
											<c:if test="${item.depar !=null && item.role !=null}">
											${item.depar}(${item.role})
											</c:if>
											<c:if test="${item.depar ==null || item.role ==null}">
											
											</c:if>
											</td>
											<td>
												<c:choose>
												<c:when test="${item.status == 6}">正常</c:when>
												<c:otherwise>停用</c:otherwise>
												</c:choose>
											</td>
											<td>
												<button type="button" class="btn btn-primary btn-xs hidden-xs" onclick="editSysUserLogin(${item.userId});">编辑</button>
												<button type="button" class="btn btn-info btn-xs hidden-xs" onclick="resetPWD(${item.userId});">重置密码</button>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
						</div>

						<jsp:include page="../../common/turnPage.jsp" />
					</div>

            </div>
            
        </div>

	</div>
    
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/jquery.min.js?v=2.1.4"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/content.min.js?v=1.0.0"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/toastr/toastr.min.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/layer/layer.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/bootstrap-table/bootstrap-table.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="<%=request.getContextPath()%>/views/sysdefault/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script type="text/javascript">
    
    var basePath = '<%=request.getContextPath()%>';
    
    toastr.options = {
  		  "closeButton": true,
  		  "debug": false,
  		  "progressBar": true,
  		  "positionClass": "toast-top-left",
  		  "showDuration": "400",
  		  "hideDuration": "1000",
  		  "timeOut": "3000",
  		  "extendedTimeOut": "1000",
  		  "showEasing": "swing",
  		  "hideEasing": "linear",
  		  "showMethod": "fadeIn",
  		  "hideMethod": "fadeOut"
  		}
    
	var addUser = function(){
    	
    	layer.open({
    		  type: 2,
    		  title: '添加用户',
    		  shadeClose: true,
    		  shade: 0.3,
    		  area: ['80%', '98%'],
    		  content: basePath + '/system/addUserLogin.do' //iframe的url
    		});
    	
    }
    
	var userInfo = function(mid){
    	
    	layer.open({
    		  type: 2,
    		  title: '用户信息',
    		  shadeClose: true,
    		  shade: 0.3,
    		  area: ['80%', '98%'],
    		  content: basePath + '/user/userInfo.dol?userId='+mid //iframe的url
    		});
    	
    }
    
	/******删除用户******/
	var delUser = function(){
		var selectIds = '';
		
		var selectItems = $("#table").bootstrapTable('getSelections');
		$.each(selectItems, function(i, item){
			selectIds = selectIds + item[1] + ',';
		});
		
		if(selectIds == ''){
			toastr.warning("请选择需要删除的用户！", "提示");
			return;
		}
		
		layer.confirm('确定要删除选中的用户吗？', {
			  btn: ['确定','取消'] //按钮
			}, function(index){
			  
				layer.close(index);
				
				$.ajax({
					type : "POST",
					url : basePath + "/system/delSysUser.do",
					data : {"ids" : selectIds},
					dataType : "json",
					success : function(msg) { 
						if (msg.errCode == '1') {
							layerCallBack('1');
						}else{
							toastr.error(msg.errMsg, "提示");
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						toastr.error("系统出错！", "提示");
					},
					beforeSend : function(XMLHttpRequest){
						layer.load(0, {
							  shade: [0.3,'#ccc'] //0.1透明度的白色背景
							});
					},
					complete : function(XMLHttpRequest, textStatus){
						layer.closeAll();
					}
				});
				
			}, function(){
			  
			});
		
	}
	
	/******重置用户密码******/
	var resetPWD = function(id){
		
		layer.confirm('确定要重置该用户密码？', {
			  btn: ['确定','取消'] //按钮
			}, function(index){
			  
				layer.close(index);
				
				$.ajax({
					type : "POST",
					url : basePath + "/system/resetPWD.do",
					data : {"id" : id},
					dataType : "json",
					success : function(msg) { 
						if (msg.errCode == '1') {
							layerCallBack('1');
						}else{
							toastr.error(msg.errMsg, "提示");
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						toastr.error("系统出错！", "提示");
					},
					beforeSend : function(XMLHttpRequest){
						layer.load(0, {
							  shade: [0.3,'#ccc'] //0.1透明度的白色背景
							});
					},
					complete : function(XMLHttpRequest, textStatus){
						layer.closeAll();
					}
				});
				
			}, function(){
			  
			});
	}
	
	var layerCallBack = function(status){
    	if(status == '1'){
    		layer.closeAll();
    		toastr.success("操作成功！", "提示");
    		
    		setTimeout(function(){
    			location.reload();
    		}, 1000);
    		
    	}else if(status == '2'){
    		layer.closeAll();
    		toastr.success("操作成功！", "提示");
    	}
    }
	
	//编辑用户
    function editSysUserLogin(id){
		
    	layer.open({
  		  type: 2,
  		  title: '编辑用户',
  		  shadeClose: true,
  		  shade: 0.3,
  		  area: ['80%', '98%'],
  		  content: basePath + '/system/editSysUserLogin.do?userId='+id //iframe的url
  		});
    }
    </script>
    
</body>

</html>